<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<title><s:property value="ev_title" /></title>
<link rel="stylesheet" href="${aier_css_url}b.css" />
<link rel="stylesheet" type="text/css" href="${aier_css_url}jp/1.css" />
<link href="${aier_css_url}jq/jq.css" rel="Stylesheet" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}/ui.css" />
<link rel="stylesheet" href="${aier_css_url}comm/text.css" />
<link rel="stylesheet" href="${aier_css_url}admin/admin.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/1.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/arrayList.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}comm/text.js"></script>

</head>
<body style="background-color: #EEF2FB;">
    
    <div style="background-color: #EEF2FB;width: 100%;height: 700px; ">

                     <div id="tabs">
                    <ul>
                        <li><a href="#tabs-1">区域管理</a></li>
                    </ul>
                    <div id="tabs-1" style="height: 500px;">
                        <div class="d_content">
                        <div style="margin-left: 400px;">
                            <div class="d_scnOut">
                                <div class="d_scname">
                                    <label for="txt_tName">省:</label>
                                </div>
                                <div class="sel_region">
                                    <s:select list="province" id="province"></s:select>
                                </div>
                            </div>
                            <div class="d_scnOut">
                                <div class="d_scname">
                                    <label for="txt_tName">市:</label>
                                </div>
                                <div class="sel_region">
                                    <select id="city"></select>
                                </div>
                            </div>
                            <div class="d_scnOut">
                                <div class="d_scname">
                                    <label for="txt_tName">区:</label>
                                </div>
                                <div class="sel_region">
                                    <select id="area"></select>
                                </div>
                            </div>
                            <div class="d_scnOut">
                                <div class="d_scname">
                                    <label for="txt_tName">街道/乡镇:</label>
                                </div>
                                <div class="sel_region">
                                    <select id="street"></select>
                                </div>
                            </div>
                            <div class="d_scnOut">
                                <div class="d_sctext" style="margin-left: 50px;margin-top: 0px;">
                                    <input type="text" id="name">
                                </div>
                            </div>
                            <div class="d_scnOut" style="margin-left: 150px;margin-top: -40px;">
                                <div class="d_scname">
                                    <label for="txt_tName">开放:</label>
                                </div>
                                <div class="d_sctext" style="margin-left: 45px;">
                                    <input type="checkbox" id="cbox">
                                </div>
                            </div>
						</div>
							<br/>
							<button onclick="update()"
                                class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                                role="button" aria-disabled="false">
                                <span class="ui-button-text">修改</span>
                            </button>
							<button onclick="add()"
                                class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                                role="button" aria-disabled="false">
                                <span class="ui-button-text">添加</span>
                            </button>
                            <button onclick="del()"
                                class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                                role="button" aria-disabled="false">
                                <span class="ui-button-text">删除</span>
                            </button>
                            <button onclick="addc()"
                                class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                                role="button" aria-disabled="false">
                                <span class="ui-button-text">添加到子列</span>
                            </button>
							
							<br/>
							<br/>
							<br/>
							<button onclick="refresh()"
                                class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                                role="button" aria-disabled="false">
                                <span class="ui-button-text">刷新缓存</span>
                            </button>
						</div>
					</div>
					</div>

    </div>
    
<script type="text/javascript">
$("#tabs").tabs(); 
var cid=-1,ctype=-1;
function loaddata(t){
var pname,cname;
if(1==t){
pname="province";cname="city";
}else if(2==t){
pname="city";cname="area";
}else if(3==t){
pname="area";cname="street";
}else if(4==t){
pname="street";
}
$("#name").val($("#"+pname+" option:selected").text());
var ts=$("#"+pname+"").val().split("_");
		cid=ts[0];
		if(10==ts[1]){
			$("#cbox").attr("checked",true);
		}else{
			$("#cbox").attr("checked","");
		}
		ctype=t;
		if(cid<=0||4==t){return;}
		var fun=function(data){
			if(1==data.s){
				var lsc=data.lsc;
				if(lsc.length>0){
				if(1==t){initSel("city");}
				else if(2==t){initSel("area");}
				else if(3==t){initSel("street");}
				for(var i=0;i<lsc.length;i++){
					var sc=lsc[i];
					$("#"+cname+"").append("<option value='"+sc.cid+"'>"+sc.name+"</option>");
				}
				if(1==t){initSel("area");initSel("street");}
				else if(2==t){initSel("street");}
			}else{
				if(1==t){initSel("city","无数据");initSel("area","无数据");initSel("street","无数据");}
				else if(2==t){initSel("area","无数据");initSel("street","无数据");}
				else if(3==t){initSel("street","无数据");}
			}
			}else{
				alert("请填入合法值");
			}
		};
		exeAjax(ajaxUrl("${aier_url}zxadminjs/city_manage_loadCity${aier_suffix}"),fun, {"cid" : cid,});
}
	$("#province").change(function(){loaddata(1);});
	$("#city").change(function(){loaddata(2);});
	$("#area").change(function(){loaddata(3);});
	$("#street").change(function(){loaddata(4);});
	function initSel(id,name){
		if(undefined==name||null==name){name="请选择";}
		$("#"+id+"").find('option').remove().end().append('<option value="-1">'+name+'</option>');
	}
	initSel("city");initSel("area");initSel("street");
	
	function update(){
		var choosed = $('#cbox').attr("checked")=="checked";
		var fun = function(data) {
			if (data.s == 1) {
				alert("修改成功");
				var cname="";
				if(ctype==1){
					cname="province";
				}else if(ctype==2){
					cname="city";
				}else if(ctype==3){
					cname="area";
				}else if(ctype==4){
					cname="street";
				}
				$("#"+cname+" option[value='"+cid+"']").remove();
				$("#"+cname+"").append("<option value='"+cid+"'>"+$('#name').val()+"</option>");
				$("#"+cname+"").val(cid);
			} else
				alert("修改失败");
		};
		exeAjax(
				ajaxUrl("${aier_url}zxadminjs/city_manage_updateCity${aier_suffix}"),
				fun, {
					"cid" : cid ,
					"name" : $('#name').val(),
					"choosed" : choosed,
				});
				
	}

	
	function add(){
		var choosed = $('#cbox').attr("checked")=="checked";
		if(ctype<=0||ctype>=4){
			alert("街道/乡镇不能添加子列");
			return
		};
		var fun = function(data) {
			if (data.s >0) {
				var cname="";
				if(ctype==1){
					cname="province";
				}else if(ctype==2){
					cname="city";
				}else if(ctype==3){
					cname="area";
				}else if(ctype==4){
					cname="street";
				}
				$("#"+cname+"").append("<option value='"+data.s+"'>"+$('#name').val()+"</option>");
				alert("添加成功");
			} else
				alert("添加失败");
		};
		exeAjax(
				ajaxUrl("${aier_url}zxadminjs/city_manage_addCity${aier_suffix}"),
				fun, {
					"cid" : cid ,
					"name" : $('#name').val(),
					"choosed" : choosed,
				});
				
	}
	
	function del(){
		var fun = function(data) {
			if (data.s >0) {
				var cname="";
				if(ctype==1){
					cname="province";
					initSel("city","无数据");initSel("area","无数据");initSel("street","无数据");
				}else if(ctype==2){
					cname="city";
					initSel("area","无数据");initSel("street","无数据");
				}else if(ctype==3){
					cname="area";
					initSel("street","无数据");
				}else if(ctype==4){
					cname="street";
				}
				$("#"+cname+" option[value='"+cid+"']").remove();
				alert("删除成功");
			} else
				alert("删除失败");
		};
		exeAjax(
				ajaxUrl("${aier_url}zxadminjs/city_manage_delCity${aier_suffix}"),
				fun, {
					"cid" : cid
				});
				
	}

	function addc(){
		var choosed = $('#cbox').attr("checked")=="checked";
		if(ctype<=0||ctype>=4){
			alert("街道/乡镇不能添加子列");
			return
		};
		var fun = function(data) {
			if (data.s >0) {
				var cname="";
				if(ctype==1){
					cname="city";
				}else if(ctype==2){
					cname="area";
				}else if(ctype==3){
					cname="street";
				}
				$("#"+cname+"").append("<option value='"+data.s+"'>"+$('#name').val()+"</option>");
				alert("添加到子列成功");
			} else
				alert("添加到子列失败");
		};
		exeAjax(
				ajaxUrl("${aier_url}zxadminjs/city_manage_addSubCity${aier_suffix}"),
				fun, {
					"cid" : cid ,
					"name" : $('#name').val(),
					"choosed" : choosed,
				});
				
	}
	
function refresh(){var fun = function(data) {if (data.s == 1){alert("刷新成功");} elsealert("刷新失败");};exeAjax(ajaxUrl("${aier_url}zxadminjs/city_manage_refresh${aier_suffix}"),fun, {});}
</script>
</body>
</html>
